﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using Lephone.Data;

namespace SimlvClient
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class Login : ModernDialog
    {
        private ICommand OKCommand;
        public Login()
        {
            InitializeComponent();
            this.OKCommand = new RelayCommand(o =>
            {
                var Model = DbEntry.From<SimlvClient.Model.User>().Where(S => S.UserName == this.txtUserName.Text && S.Password == this.txtPassword.Password).OrderByDescending(S => S.Id).Select().SingleOrDefault();
                if (Model != null)
                {
                    MainWindow windowModel = new MainWindow();
                    windowModel.Show();
                    this.Close();
                }
                else
                {

                    ModernDialog.ShowMessageText("登录失败,请重试！");
                }
                
            });
            Buttons = new[] {
               new Button {
                Content = "登录",
                Command = OKCommand,
                IsDefault = true,
                IsCancel = false,
                MinHeight = 21,
                MinWidth = 65,
                Margin = new Thickness(4, 0, 0, 0)
            }, CancelButton
            };
           
            this.Show();
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            
           
        }

      
    }
}
